<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
    <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
    <script src="${pageContext.request.contextPath}/public/bootstrap/js/bootstrap.min.js"></script>
</head>
<style>
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 90px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
    height:30px;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}

</style>
<body>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看所有通知消息</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" data-toggle="modal" data-target="#myModal" ><i class="icon-font"></i>发布通知消息</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>消息ID</th>
                            <th>消息标题</th>
                            <th>发布时间</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${pageinfo.list}" var="v">
                        <tr >
                            <td>${v.systemNoticeId}</td>
                            <td>${v.systemNoticeTitle }</td>
                            <td><fmt:formatDate value="${v.systemNoticeDate }" pattern="yyyy-MM-dd/HH:mm:ss"/></td>
                            <td>
                            <button type="button" class="btn btn-success" onclick="updateget(${v.systemNoticeId})" data-toggle="modal" data-target="#myModal">修改</button>
                            <button type="button" class="btn btn-danger" onclick="dele(${v.systemNoticeId})">删除</button>
                            </td>
                            </tr>
  					</c:forEach>
                    </table>
                    
                </div>
        </div>
               <div class="row">
				<div class="col-md-6">当前${pageinfo.getPageNum() }页,总${pageinfo.getPages() }
				页,总${pageinfo.getTotal()}条记录</div>
                <div class="col-md-6">
				<nav aria-label="Page navigation">
				<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/systemnotice/notice.action?pn=1">首页</a></li>
					<c:if test="${pageInfo.hasPreviousPage }">
						<li><a href="${pageContext.request.contextPath}/systemnotice/notice.action?pn=${pageInfo.pageNum-1}"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>


					<c:forEach items="${pageinfo.navigatepageNums }" var="page_Num">
						<c:if test="${page_Num == pageinfo.pageNum }">
							<li class="active"><a href="#">${page_Num }</a></li>
						</c:if>
						<c:if test="${page_Num != pageinfo.pageNum }">
							<li><a href="${pageContext.request.contextPath}/systemnotice/notice.action?pn=${page_Num }">${page_Num }</a></li>
						</c:if>

					</c:forEach>
					<c:if test="${pageinfo.hasNextPage }">
						<li><a href="${pageContext.request.contextPath}/systemnotice/notice.action?pn=${pageinfo.pageNum+1 }"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/systemnotice/notice.action?pn=${pageinfo.pages}">末页</a></li>
				</ul>
				</nav>
			</div>
			</div>
    </div>
</div>

<div  class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header" >
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					发布通知
				</h4>
			</div>
			<div >
			<form>
				<table  class="addtab" id="cont">
				<tr><th><i class="require-red">*</i>消息标题：</th><td><input  name='systemNoticeTitle' type="text"  placeholder="消息标题"></td></tr>
				<tr><th><i class="require-red">*</i>消息内容：</th></br><td><textarea name="systemNoticeContent" placeholder="请输入消息内容！" rows="5" cols="43"></textarea></td></tr>
				</table>
		</form>
		</div>
			<div class="modal-footer" id="foot" style="border-top:none;">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					关闭
				</button>
				<button type="button" class="btn btn-primary" onclick="add()">
					提交
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script>
   $(function () { $('#myModal').modal('hide')});
</script>
<script>
   $(function () { $('#myModal').on('hide.bs.modal', function () { })
   });
</script>
<script type="text/javascript">

function dele(systemNoticeId)
{
	$.get("${pageContext.request.contextPath}/systemnotice/deletenotice.action",{systemNoticeId:systemNoticeId},function(returndata){
		if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
}

function updateget(systemNoticeId)
{
	$.get("${pageContext.request.contextPath}/systemnotice/updatenotice.action",{systemNoticeId:systemNoticeId},function(returndata){
		if(returndata.code==1)
		{
			var systemNoticeTitle=returndata.data.systemNotice.systemNoticeTitle;
			var systemNoticeContent=returndata.data.systemNotice.systemNoticeContent;
			var str="<tr><th><i class='require-red'>*</i>消息标题：</th><td><input  name='systemNoticeTitle2' type='text' value='"+systemNoticeTitle+"' placeholder='消息标题'></td></tr>";
			str+="<tr><th><i class='require-red'>*</i>消息内容：</th></br><td><textarea name='systemNoticeContent2' placeholder='请输入消息内容！' rows='5' cols='43'>"+systemNoticeContent+"</textarea></td></tr>";
			str+="<input name='systemNoticeId2' type='hidden' value='"+systemNoticeId+"'/>";
			$("#cont").html(str);
			var str2="<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>";
			str2+="<button type='button' class='btn btn-primary' onclick='upd()'>提交</button>";
			$("#foot").html(str2);
		}
	});
}

function upd()
{
	var systemNoticeTitle=$("input[name=systemNoticeTitle2]");
	var systemNoticeContent=$("textarea[name=systemNoticeContent2]");
	var systemNoticeId=$("input[name=systemNoticeId2]");
	if(systemNoticeTitle.val()=="")
	{
        layer.msg('消息标题不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        systemNoticeTitle.focus();
        return ;		
	}
	if(systemNoticeContent.val()=="")
	{
        layer.msg('消息内容不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        systemNoticeContent.focus();
        return ;		
	}
	$.post("${pageContext.request.contextPath}/systemnotice/updatefun.action",{systemNoticeTitle:systemNoticeTitle.val(),systemNoticeContent:systemNoticeContent.val(),systemNoticeId:systemNoticeId.val()},function(returndata){
		if(returndata.code==1){
			$(function () { $('#myModal').modal('hide')});
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		}
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 

	});
}

function add()
{
	var systemNoticeTitle=$("input[name=systemNoticeTitle]");
	var systemNoticeContent=$("textarea[name=systemNoticeContent]");
	if(systemNoticeTitle.val()=="")
	{
        layer.msg('消息标题不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        systemNoticeTitle.focus();
        return ;		
	}
	if(systemNoticeContent.val()=="")
	{
        layer.msg('消息内容不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        systemNoticeContent.focus();
        return ;		
	}
	
	$.post("${pageContext.request.contextPath}/systemnotice/insertnotice.action",{systemNoticeTitle:systemNoticeTitle.val(),systemNoticeContent:systemNoticeContent.val()},function(returndata){
		if(returndata.code==1){
			$(function () { $('#myModal').modal('hide')});
			location.reload(); 
		}
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 

	});
}

</script>
</html>